package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelPageDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 文章列表控制
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    //Service
    private final WmChannelService wmChannelService;

    /**
     * 查看所有频道
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult findAll(){
        log.info("查看所有频道");

        return wmChannelService.findAll();
    }


    /**
     * 新增频道
     *
     * @param  wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel) {

        log.info("管理端保存频道....");

        return wmChannelService.saveChannel(wmChannel);

    }


    /**
     * 分页查询频道
     *
     * @param  wmChannelPageDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listChannel(@RequestBody WmChannelPageDto wmChannelPageDto) {

        log.info("管理端分页查询频道....");

        return wmChannelService.listChannel(wmChannelPageDto);

    }



    /**
     * 修改频道
     *
     * @param   wmChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel) {

        log.info("管理端修改频道....");

        return wmChannelService.updateChannel(wmChannel);

    }


    /**
     * 删除频道
     *
     * @param   id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id) {

        log.info("管理端修删除频道....");

        return wmChannelService.deleteChannel(id);

    }
}





















